﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AcSDK.Core;
using AcSDK.Util;

namespace AcSDK.Request
{
    /// <summary>
    /// 基础请求类，存放一些通用的请求参数.
    /// </summary>
    public abstract class BaseAcRequest<T, U> : IAcRequest<T> where T : AcResponseBase  where U:AcObject,new()
    {

       
       private U instance = new U();

        /// <summary>
        /// HTTP请求URL参数
        /// </summary>
        internal AcDictionary otherParams;
        /// <summary>
        /// HTTP请求头参数
        /// </summary>
        private AcDictionary headerParams;
        /// <summary>
        /// 请求目标AppKey
        /// </summary>
        private string targetAppKey;

        public void AddOtherParameter(string key, string value)
        {
            if (this.otherParams == null)
            {
                this.otherParams = new AcDictionary();
            }
            this.otherParams.Add(key, value);
        }

        public void AddHeaderParameter(string key, string value)
        {
            GetHeaderParameters().Add(key, value);
        }

        public IDictionary<string, string> GetHeaderParameters()
        {
            if (this.headerParams == null)
            {
                this.headerParams = new AcDictionary();
            }
            return this.headerParams;
        }

        public string GetTargetAppKey()
        {
            return this.targetAppKey;
        }

        public void SetTargetAppKey(string targetAppKey)
        {
            this.targetAppKey = targetAppKey;
        }

        public abstract string GetApiName();

        public abstract void Validate();

        public abstract IDictionary<string, string> GetParameters();

        public string RequestBody
        {
            get { return JsonHelper.SerializeObject(Instance); }
        }


        public U Instance
        {
            get
            {
                return instance;
            }
            set { instance = value; }
        }

    }
}
